package com.pen.interfece.controller.admin;

import com.pen.interfece.pojo.PageResult;
import com.pen.interfece.pojo.Result;
import com.pen.interfece.pojo.dto.DisciplinaryPageQueryDTO;
import com.pen.interfece.pojo.dto.DormitoryPageQueryDTO;
import com.pen.interfece.pojo.dto.StudentDTO;
import com.pen.interfece.pojo.dto.StudentPageQueryDTO;
import com.pen.interfece.pojo.entity.Disciplinary;
import com.pen.interfece.pojo.entity.Dormitory;
import com.pen.interfece.pojo.entity.Student;
import com.pen.interfece.pojo.vo.StudentVO;
import com.pen.interfece.service.DormitorySerivice;
import com.pen.interfece.service.StudentSerivice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stu")
@Slf4j
public class StudentController {
    @Autowired
    private StudentSerivice studentSerivice;

    @GetMapping("/page")
    public Result<PageResult> page(@RequestBody StudentPageQueryDTO studentPageQueryDTO){
        log.info("学生分页查询：参数为：{}",studentPageQueryDTO);
        PageResult pageResult=studentSerivice.pageQuery(studentPageQueryDTO);
        return Result.success(pageResult);
    }
    //新增学生
    @PostMapping("/add")//此时的id是宿舍id
    public Result save(@RequestBody StudentDTO studentdto,@RequestParam int id){
        log.info("新增学生：{}",studentdto,id);
        studentSerivice.save(studentdto,id);
        return Result.success("增加成功");
    }

    //删除学生
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids)
    {
        log.info("学生批量删除：{}",ids);
        studentSerivice.deleteBatch(ids);
        return Result.success("删除成功");
    }
    @PutMapping
    public Result update(@RequestBody StudentDTO studentDTO){
        log.info("学生修改：{}",studentDTO);
        studentSerivice.update(studentDTO);
        return Result.success("修改成功");
    }
    @PostMapping("/add2")
    public Result addDisciplinary(@RequestBody Disciplinary disciplinary,@RequestParam int id){
        log.info("学生增加违纪");
        studentSerivice.addDisciplinary(disciplinary,id);
        return Result.success("添加成功");

    }



}